package com.hucheng.seckill.entity;

import com.hucheng.common.utils.CommonUtils;
import com.hucheng.seckill.dto.OrderInfoDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 持久层数据
 **/
@Data
public class OrderInfoDO {
    private Integer orderId;
    private String orderNumber;
    private Integer userId;
    private Integer status;
    private BigDecimal orderAmount;
    private BigDecimal payAmount;
    private BigDecimal totalAmount;
    private Date datePay;
    private Integer addressId;
    private String remark;
    private Integer isDel;
    private Timestamp dateCreated;
    private Timestamp dateUpdated;

    public static OrderInfoDO buildOrderInfoDO(final OrderInfoDTO orderDTO) {
        if (orderDTO != null) {
            OrderInfoDO orderDO = new OrderInfoDO();

            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(orderDTO.getOrderId()+"")) {
                orderDO.setOrderId(orderDTO.getOrderId());
                orderDO.setOrderNumber(CommonUtils.getOrderIdByTime());
                orderDO.setDateCreated(currentTime);
            }else{
                orderDO.setDateUpdated(currentTime);
            }
            orderDO.setUserId(orderDTO.getUserId());
            orderDO.setStatus(orderDTO.getStatus());
            orderDO.setOrderAmount(orderDTO.getOrderAmount());
            orderDO.setPayAmount(orderDTO.getPayAmount());
            orderDO.setTotalAmount(orderDTO.getTotalAmount());
            orderDO.setDatePay(orderDTO.getDatePay());
            orderDO.setAddressId(orderDTO.getAddressId());
            orderDO.setRemark(orderDTO.getRemark());
            orderDO.setIsDel(0);
            return orderDO;
        }
        return null;
    }
}
